
package cn.hs.blog.base;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;

public class ActionUtils {
    
    private static final Logger log = Logger.getLogger(ActionUtils.class.getName());
    
    /**
     * 用request中的数据填充obj中的属性
     * 
     * @param request
     * @param obj
     */
    @SuppressWarnings("unchecked")
    public static void populate(HttpServletRequest request, Object obj) {

        Map map = request.getParameterMap();
        try {
            BeanUtils.populate(obj, map);
        } catch (IllegalAccessException e) {
            log.warning(e.getMessage());
            // e.printStackTrace();
        } catch (InvocationTargetException e) {
            log.warning(e.getMessage());
            // e.printStackTrace();
        }
    }

}
